package com.sun.abilities.recursion;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;

import com.sun.abilities.recursion.base.Node;

public class NodeInfo {
	public static void main(String[] args) {
		Node r = new Node("r");
		Node r1 = new Node("r1");
		Node r2 = new Node("r2");
		Node r1_1 = new Node("r1_1");
		Node r1_2 = new Node("r1_2");
		Node r1_3 = new Node("r1_3");
		Node r2_1 = new Node("r2_1");
		Node r2_2 = new Node("r2_2");
		Node r1_1_1 = new Node("r1_1_1");
		Node r1_1_2 = new Node("r1_1_2");
		Node r2_1_1 = new Node("r2_1_1");
		Node r2_1_2 = new Node("r2_1_2");
		Node r2_1_3 = new Node("r2_1_3");
		r.getChildren().add(r1);
		r.getChildren().add(r2);
		r1.getChildren().add(r1_1);
		r1.getChildren().add(r1_2);
		r1.getChildren().add(r1_3);
		r1_1.getChildren().add(r1_1_1);
		r1_1.getChildren().add(r1_1_2);
		r2.getChildren().add(r2_1);
		r2.getChildren().add(r2_2);
		r2_1.getChildren().add(r2_1_1);
		r2_1.getChildren().add(r2_1_2);
		r2_1.getChildren().add(r2_1_3);
		List<List<Node>> lss = new ArrayList<>();
		iterator(r, new Stack<Node>(), lss);
	}

	public static void iterator(Node n, Stack<Node> pathstack, List<List<Node>> lss) {
		pathstack.push(n);
		List<Node> nodes = n.getChildren();
		if (!nodes.isEmpty()) {
			for (Node node : nodes) {
				iterator(node, pathstack, lss);
				pathstack.pop();
			}
		} else {
			Iterator<Node> stackIt = pathstack.iterator();
			while (stackIt.hasNext()) {
				System.out.print(stackIt.next().getId() + "--");
			}
			System.out.println();
		}
		
	} 
}
